package cn.itcast.service.cargo.impl;


import cn.itcast.dao.cargo.InvoiceDao;
import cn.itcast.dao.cargo.ShippingDao;
import cn.itcast.domain.cargo.Invoice;
import cn.itcast.domain.cargo.InvoiceExample;
import cn.itcast.service.cargo.InvoiceService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.UUID;

@Service
public class InvoiceServiceImpl implements InvoiceService {


    @Autowired
    private InvoiceDao invoiceDao;

    private ShippingDao shippingDao;

    /*
     发票分页
     */
    @Override
    public PageInfo<Invoice> findByPage(InvoiceExample invoiceExample, int pageNum, int pageSize) {

        //设置页面大小
        PageHelper.startPage(pageNum,pageSize);

        //查询全部
        List<Invoice> invoiceList = invoiceDao.selectByExample(invoiceExample);

        //封装PageInfo对象
        PageInfo<Invoice> pageInfo = new PageInfo<>(invoiceList);

        return pageInfo;
    }

    //查询全部
    @Override
    public List<Invoice> findAll(InvoiceExample invoiceExample) {

        List<Invoice> invoiceList = invoiceDao.selectByExample(invoiceExample);

        return invoiceList;
    }

    //根据主键查询
    @Override
    public Invoice findById(String id) {

        Invoice invoice = invoiceDao.selectByPrimaryKey(id);
        return invoice;
    }


    //保存发票
    @Override
    public void save(Invoice invoice) {
        //设置发票id
        invoice.setInvoiceId(UUID.randomUUID().toString());

        //设置发票状态
        invoice.setStatus("0");
        invoiceDao.insertSelective(invoice);

        //修改委托单状态


    }

    //更新发票
    @Override
    public void update(Invoice invoice) {
        //发票的更新时间
        invoiceDao.updateByPrimaryKeySelective(invoice);
    }

    //删除发票
    @Override
    public int delete(String id) {
        return invoiceDao.deleteByPrimaryKey(id);
    }

    @Override
    public List<Invoice> findAll1() {
        return invoiceDao.findAll1();
    }

}
